import SwiftUI

struct Post: Identifiable {
  let id = UUID()
  let image: String
  let title: String
}

struct IndexView: View {
  let posts = [
    Post(image: "loginPicture", title: "Beautiful Sunset"),
    Post(image: "loginPicture", title: "Cute Puppy"),
    Post(image: "loginPicture", title: "Delicious Food"),
    Post(image: "loginPicture", title: "Amazing Landscape"),
    Post(image: "loginPicture", title: "Funny Memes"),
    Post(image: "loginPicture", title: "Awesome Nature"),
    Post(image: "loginPicture", title: "Inspiring Quotes"),
    Post(image: "loginPicture", title: "Cool Street Art")
  ]
  
  let columns = [
    GridItem(.flexible()),
    GridItem(.flexible())
  ]
  
  var body: some View {
    ScrollView {
      LazyVGrid(columns: columns, spacing: 16) {
        ForEach(posts) { post in
            NavigationLink(destination: PostDetailView(post: post)) {
                VStack(alignment: .leading) {
                    Image(post.image)
                        .resizable()
                        .aspectRatio(contentMode: .fit)
                    
                    Text(post.title)
                        .font(.headline)
                        .foregroundColor(.primary)
                        .lineLimit(2)
                }
            }
        }
      }
      .padding(.horizontal)
      .padding(.top, 16)
      .padding(.bottom, 32)
    }
  }
}

struct IndexView_Previews: PreviewProvider {
  static var previews: some View {
      IndexView()
  }
}
